import pymysql

host = "localhost"
user = "root"
password = "root"
port = 3308
db = "py"

def update(sql,param = None):
    coon = pymysql.connect(host=host, user=user, password=password, db=db, port=port, charset='utf8')
    try:
        with coon.cursor() as cur:
            cur.execute(sql,param)
            coon.commit()
    except Exception as e:
        print("数据库操作异常：",e)
    finally:
        cur.close()
        coon.close()
def select(sql,param = None):
    coon = pymysql.connect(host=host, user=user, password=password, db=db, port=port, charset='utf8')
    try:
        with coon.cursor() as cur:
            cur.execute(sql,param)
            result = cur.fetchone()
            print(result)
    except Exception as e:
        print("数据库操作异常：",e)
    finally:
        cur.close()
        coon.close()

